<?php

define('IN_QY', true);
session_start();
require("include/common.inc.php");
require('include/functions.php');
require('sku_model.php');
//$_COOKIE['userid'] = '151202475870';
if (!$_COOKIE['userid']) {
    echo "<script type='text/javascript'>location.href='login.php';</script>";
    exit;
}

$order_id = $_GET['oid'];
$sql = "select * from tbl_taorder where uid='" . $_COOKIE['userid'] . "' and is_pay = 0 and orderid='" . $order_id . "'";
$query = mysql_query($sql);
$resu = mysql_fetch_array($query);
if (!$resu) {
    echo "<script type='text/javascript'>alert('订单不存在!');history.go(-1);</script>";
    exit;
}
$sql = "select * from tbl_taorder where uid='" . $_COOKIE['userid'] . "' and orderid='" . $order_id . "' and is_pay=1";
$query = mysql_query($sql);
$resut = mysql_fetch_array($query);
if ($resut) {
    echo "<script type='text/javascript'>alert('订单已支付!');history.go(-1);</script>";
    exit;
}

//优惠券判断
$coupon0 = array();//饼干
$coupon1 = array();//牙膏
$coupon2 = array();//洗洁精
$coupon3 = array();//香皂
$coupon4 = array();//酒水饮料
$coupon5 = array();//麦片奶粉
$coupon6 = array();//全品类
$coupon7 = array();//红酒
$sql = "select t1.*,t2.typeid,t2.ggnum,t2.typeid,t2.entitle,t2.encode from tbl_taorder t1 inner join tbl_taospp t2 on t1.goodid=t2.id where t1.orderid='" . $order_id . "'";
$query = mysql_query($sql);
while ($rowhyq = mysql_fetch_array($query)) {
    $totpri = $rowhyq['gnum'] * $rowhyq['gprice'];//总价
    $coupon6[] = $totpri;
    if ($rowhyq['typeid'] == 2) {
        $coupon4[] = $totpri;
    }
    if ($rowhyq['entitle'] == 7) {
        $coupon0[] = $totpri;
    } elseif ($rowhyq['entitle'] == 15) {
        $coupon1[] = $totpri;
    } elseif ($rowhyq['entitle'] == 14) {
        $coupon2[] = $totpri;
    } elseif ($rowhyq['entitle'] == 12) {
        $coupon3[] = $totpri;
    } elseif ($rowhyq['entitle'] == 5 || $rowhyq['entitle'] == 6) {
        $coupon5[] = $totpri;
    } elseif ($rowhyq['entitle'] == 9) {
        $coupon7[] = $totpri;
    }
}

//地址变更重新计算运费
if ($_GET['youb']) {
    $proarr1 = array(9, 1, 10, 11, 16, 18, 17, 12, 14, 19);
    $proarr2 = array(3, 2, 13, 22, 15, 23, 20, 21);
    $proarr3 = array(27, 4, 7, 24, 6, 25, 8, 5, 28, 29, 30);
    $proarr4 = array(26);
    $proarr5 = array(31);
    $numarr = array();
    $numarr1 = array();
    $weiarr = array();
    $priarr = array();
    $tempyb = $_GET['youb'];

    $sql = "select t1.*,t2.typeid,t2.ggnum,t2.typeid,t2.entitle,t2.encode from tbl_taorder t1 inner join tbl_taospp t2 on t1.goodid=t2.id where t1.orderid='" . $order_id . "'";
    $query = mysql_query($sql);

    while ($row = mysql_fetch_array($query)) {


        $totpri = $row['gnum'] * $row['gprice'];//总价
//        if ($row['entitle'] != 9) {
        $priarr[] = $totpri;
//        }

        if ($row['sku_id']) {
            $sku_info = c_getRow("select * from tbl_goods_sku WHERE id = " . $row['sku_id']);
            $sku_weight = $sku_info['sku_weight'];
        }

        $weight = "";//重量
        $d_w = $row['encode']; // 单价重量
        if ($sku_weight) {
            $d_w = $sku_weight;
        }

        // 如果是红酒就包邮 cj
        $baoyou = c_getRows("select type from tbl_sb_baoyou");
        if (in_array($row['entitle'], array_column($baoyou, 'type'))) {
            $d_w = 0;
        }

        $weight = $row['gnum'] * $d_w;
        $weiarr[] = $weight;

    }
    //运费
//    $delinum = array_sum($numarr);
//    $delinum1 = array_sum($numarr1);
//    $delifee = $delinum * 40;
//    $delifee1 = $delinum1 * 20;
    $wei = array_sum($weiarr);
    $weis = ceil($wei);
    $pri = array_sum($priarr);
    $express = "";

    if ($wei == 0) {
        $express = 0;
    } elseif ($wei <= 1 && $wei > 0) {
        if (in_array($tempyb, $proarr1)) {
            $express = 12;
        } elseif (in_array($tempyb, $proarr2)) {
            $express = 15;
        } elseif (in_array($tempyb, $proarr3)) {
            $express = 20;
        } elseif (in_array($tempyb, $proarr4)) {
            $express = 25;
        } elseif (in_array($tempyb, $proarr5)) {
            $express = 30;
        }
    } else {
        if (in_array($tempyb, $proarr1)) {
            $express = 12 + ($weis - 1) * 5;
        } elseif (in_array($tempyb, $proarr2)) {
            $express = 15 + ($weis - 1) * 8;
        } elseif (in_array($tempyb, $proarr3)) {
            $express = 20 + ($weis - 1) * 10;
        } elseif (in_array($tempyb, $proarr4)) {
            $express = 25 + ($weis - 1) * 20;
        } elseif (in_array($tempyb, $proarr5)) {
            $express = 30 + ($weis - 1) * 18;
        }
    }


//    $totfee = $delifee + $delifee1 + $express;
    $totfee = $express;

    //taocart
    $sql = "select max(id) AS oid from tbl_taorder where orderid='" . $order_id . "'";
    $query = mysql_query($sql);
    $res = mysql_fetch_array($query);
    $sql = "update tbl_taorder set expresstri='" . $totfee . "' where id='" . $res['oid'] . "'";
    mysql_query($sql);
}


?>

<?php
$sql = "select sum(totprice) as goods_total_money, sum(totprice+expresstri) as totfee,sum(expresstri) as totexp from tbl_taorder where orderid='" . $order_id . "'";
$query = mysql_query($sql);
$rowfee = mysql_fetch_array($query);

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>订单</title>
    <link rel="stylesheet" href="/ui/layui/css/layui.css">
    <link href="/ui/two/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css"/>
    <link href="/ui/two/basic/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/ui/two/css/cartstyle.css" rel="stylesheet" type="text/css"/>
    <link href="/ui/two/css/jsstyle.css" rel="stylesheet" type="text/css"/>
    <script src="/sy/adz/js/jquery.min.js"></script>
    <script type="text/javascript" src="fetch/js/address.js"></script>
    <script src="/ui/layui/layui.js"></script>
    <script src="/ui/layer/layer.js"></script>
    <style>
        #searchnav {
            height: 20px;
            text-align: center;
            margin-left: 18px;
        }

        #searchnav p {
            height: 100%;
            width: 48px;
            margin-right: 6px;
            border-radius: 10px 10px 0 0;
            float: left;
            cursor: pointer;
            color: #fff;
            background: linear-gradient(#f86b54, #dc4835);
        }
    </style>
</head>

<body onmousemove="Aaa()">

<!--顶部导航条 -->
<? include('head1.php'); ?>

<form action="taorderconf.php" method="post" onsubmit="return checktax()">
    <input type="hidden" name="orderid" value="<?php echo $order_id; ?>">
    <div class="concent">
        <!--地址 -->
        <div class="paycont">
            <div class="address">
                <h3>确认收货地址 </h3>
                <div class="control">
                    <div class="tc-btn createAddr theme-login am-btn am-btn-danger"><a href="/vip/9999.php">使用新地址</a>
                    </div>
                </div>
                <div class="clear"></div>
                <ul>
                    <div class="per-border"></div>
                    <?php
                    $sql = "select * from tbl_address where userid='" . $_COOKIE['userid'] . "' order by moren+0 desc limit 3";
                    $query = mysql_query($sql);
                    while ($row = mysql_fetch_array($query)) {
                        ?>

                        <li class="user-addresslist <?php if ($row['moren'] == 1) {
                            echo "defaultAddr";
                        }; ?> ">

                            <div class="address-left">
                                <div class="user DefaultAddr">

                    <span class="buy-address-detail">
                                <span class="buy-user"><?php echo $row['name']; ?></span>
                      <span class="buy-phone"><?php echo $row['tell']; ?></span>
                    </span>
                                </div>
                                <div class="default-address DefaultAddr">
                                    <span class="buy-line-title buy-line-title-type">收货地址：</span>
                                    <span class="buy--address-detail">
                      <?php echo $row['diqu']; ?><?php echo $row['dizhi']; ?>
                    </span>
                                </div>
                                <?php if ($row['moren'] == 1) { ?>
                                    <ins class="deftip">默认地址</ins>
                                <?php } ?>
                            </div>
                            <div class="address-right">
                                <span class="am-icon-angle-right am-icon-lg"></span>
                            </div>
                            <div class="clear"></div>

                            <div class="new-addr-btn">
                                <?php if ($row['moren'] == 0) { ?>
                                    <a href="addchange.php?aid=<?php echo $row['id']; ?>&oid=<?php echo $order_id; ?>"><span
                                                id="addmo" style="cursor:pointer">设为默认</span></a>
                                <?php } ?>

                            </div>

                        </li>
                    <?php } ?>


                </ul>

                <div class="clear"></div>
            </div>

            <!--订单 -->
            <div class="concent">
                <div id="payTable">
                    <?
                    $flag1 = c_getRows("select t1.*,t2.chtitle,t2.img,t2.unit,t2.ggunit,t2.hotlevel from tbl_taorder t1 LEFT join tbl_taospp t2 on t1.goodid=t2.id where t1.is_pay = 0 AND t2.ggunit=0 AND t1.orderid='" . $order_id . "'");
                    if ($flag1) { ?>
                        <h3>自营商品信息</h3>
                        <div class="cart-table-th">
                            <div class="wp">

                                <div class="th th-item">
                                    <div class="td-inner">商品信息</div>
                                </div>
                                <div class="th th-price">
                                    <div class="td-inner">单价</div>
                                </div>
                                <div class="th th-amount">
                                    <div class="td-inner">数量</div>
                                </div>
                                <div class="th th-sum">
                                    <div class="td-inner">金额</div>
                                </div>
                                <!-- <div class="th th-oplist">
                                  <div class="td-inner">配送费</div>
                                </div> -->

                            </div>
                        </div>
                    <? } ?>
                    <div class="clear"></div>
                    <?php
                    // 自营的商品
                    $sql = "select t1.*,t2.chtitle,t2.img,t2.unit,t2.ggunit,t2.hotlevel from tbl_taorder t1 LEFT join tbl_taospp t2 on t1.goodid=t2.id where t1.is_pay = 0 AND t2.ggunit=0 AND t1.orderid='" . $order_id . "'";
                    $querytao = mysql_query($sql);
                    while ($row = mysql_fetch_array($querytao)) {
                    $temp = $row['img'];
                    $imgarr = explode(",", $temp);
                    ?>
                    <div class="bundle  bundle-last">

                        <div class="bundle-main">
                            <ul class="item-content clearfix">
                                <div class="pay-phone">
                                    <li class="td td-item">
                                        <div class="item-pic">
                                            <a href="taogoodetail.php?id=<?php echo $row['goodid']; ?>"
                                               class="J_MakePoint">
                                                <img src="<?php echo $imgarr[0]; ?>" width="80" height="80"
                                                     class="itempic J_ItemImg"></a>
                                        </div>
                                        <div class="item-info">
                                            <div class="item-basic-info">
                                                <a href="taogoodetail.php?id=<?php echo $row['goodid']; ?>"
                                                   class="item-title J_MakePoint"
                                                   data-point="tbcart.8.11"><?php echo $row['chtitle']; ?></a>
                                            </div>
                                        </div>
                                    </li>
                                    <li class="td td-info">
                                        <div class="item-props">
                            <span class="sku-line">
                                <?php if ($row['bunit']) {
                                    list($r1, $r2, $sku_price, $sku_store, $r3) = get_sku_info_by_id($row['bunit']);
                                    foreach ($r3 as $sk) {
                                        $sku_key_name = $sk['sku_key_name'];
                                        $sku_value_name = $sk['sku_value_name'];
                                        echo '<span style="float: left;margin-left: 60px">' . $sku_key_name . '：' . $sku_value_name . '</span><br>';
                                    }
                                } ?>
                            </span>
                                        </div>

                                    </li>
                                    <li class="td td-price">
                                        <div class="item-price price-promo-promo">
                                            <div class="price-content">
                                                <em class="J_Price price-now"><?php echo floatval($row['gprice']); ?></em>
                                            </div>
                                        </div>
                                    </li>
                                </div>
                                <li class="td td-amount">
                                    <div class="amount-wrapper ">
                                        <div class="item-amount ">
                                            <span class="phone-title">购买数量</span>
                                            <div class="sl">
                                                <em class="J_Price price-now"><?php echo $row['gnum']; ?></em>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="td td-sum">
                                    <div class="td-inner">
                                        <em tabindex="0"
                                            class="J_ItemSum number"><?php echo floatval($row['totprice']); ?></em>
                                    </div>
                                </li>
                                <!--  <li class="td td-oplist">
                        <div class="td-inner">
                          <span class="phone-title">配送费</span>
                          <div class="pay-logis">
                            <b class="sys_item_freprice"><?php echo floatval($row['expresstri']); ?></b>元
                          </div>
                        </div>
                      </li> -->

                            </ul>
                            <div class="clear"></div>

                        </div>
                        <?php } ?>
                        <!--优惠券 -->
                        <? if ($flag1) { ?>
                            <div class="pay-total">
                                <div class="order-extra" style="width:100%;">
                                    <div class="order-user-info" style="float:left;">
                                        <div id="holyshit257" class="memo">
                                            <label>优惠券使用：</label>
                                        </div>
                                    </div>
                                    <div style="float:right;">

                                        <select name="yhq" id="yhq">
                                            <option value="">选择优惠券</option>
                                            <!--25 -->
                                            <?php
                                            $z = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=25";
                                            $x = mysql_query($z);
                                            $rows25 = mysql_fetch_array($x);
                                            if ($rows25) {
                                                $coupon70 = array_sum($coupon7);
                                                if ($coupon70 >= 399) {
                                                    ?>
                                                    <option value="<?php echo $rows25['money'] . 'and' . $rows25['id']; ?>"
                                                            style="text-align: center;">
                                                        代金券：￥<?php echo $rows25['money'] ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                            <!--20 -->
                                            <?php
                                            $z = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=20";
                                            $x = mysql_query($z);
                                            $rows20 = mysql_fetch_array($x);
                                            if ($rows20) {
                                                $coupon60 = array_sum($coupon6);
                                                if ($coupon60 >= 500) {
                                                    ?>
                                                    <option value="<?php echo $rows20['money'] . 'and' . $rows20['id']; ?>"
                                                            style="text-align: center;">
                                                        代金券：￥<?php echo $rows20['money'] ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                            <!--10 -->
                                            <?php
                                            $z = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=10";
                                            $x = mysql_query($z);
                                            $rows10 = mysql_fetch_array($x);
                                            if ($rows10) {
                                                $coupon40 = array_sum($coupon4);
                                                $coupon50 = array_sum($coupon5);
                                                if ($coupon40 >= 199 || $coupon50 >= 159) {
                                                    ?>
                                                    <option value="<?php echo $rows10['money'] . 'and' . $rows10['id']; ?>"
                                                            style="text-align: center;">
                                                        代金券：￥<?php echo $rows10['money'] ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                            <!--3 -->
                                            <?php
                                            $z = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=3";
                                            $x = mysql_query($z);
                                            $rows3 = mysql_fetch_array($x);
                                            if ($rows3) {
                                                $coupon30 = array_sum($coupon3);
                                                if ($coupon30 >= 79) {
                                                    ?>
                                                    <option value="<?php echo $rows3['money'] . 'and' . $rows3['id']; ?>"
                                                            style="text-align: center;">
                                                        代金券：￥<?php echo $rows3['money'] ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                            <!--2 -->
                                            <?php
                                            $z = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=2";
                                            $x = mysql_query($z);
                                            $rows2 = mysql_fetch_array($x);
                                            if ($rows2) {
                                                $coupon00 = array_sum($coupon0);
                                                $coupon10 = array_sum($coupon1);
                                                $coupon20 = array_sum($coupon2);
                                                if ($coupon00 >= 59 || $coupon10 >= 39 || $coupon20 >= 59) {
                                                    ?>
                                                    <option value="<?php echo $rows2['money'] . 'and' . $rows2['id']; ?>"
                                                            style="text-align: center;">
                                                        代金券：￥<?php echo $rows2['money'] ?></option>
                                                <?php } ?>
                                            <?php } ?>

                                        </select>

                                    </div>
                                </div>
                            </div>
                        <? } ?>
                        <!-- 自营商品信息end -->
                        <?php
                        // 非自营的商品，第三方
                        $sql = "select t1.*,t2.chtitle,t2.img,t2.unit,t2.hotlevel from tbl_taorder t1 LEFT join tbl_taospp t2 on t1.goodid=t2.id where t1.is_pay = 0 AND t2.ggunit<>0 AND t1.orderid='" . $order_id . "'";
                        $querytao = mysql_query($sql);
                        $flag2 = c_getRows($sql);
                        if ($flag2) {

                            echo ' <h3>第三方商品信息</h3>
              <div class="cart-table-th">
                <div class="wp">

                  <div class="th th-item">
                    <div class="td-inner">商品信息</div>
                  </div>
                  <div class="th th-price">
                    <div class="td-inner">单价</div>
                  </div>
                  <div class="th th-amount">
                    <div class="td-inner">数量</div>
                  </div>
                  <div class="th th-sum">
                    <div class="td-inner">金额</div>
                  </div>
                  <!-- <div class="th th-oplist">
                    <div class="td-inner">配送费</div>
                  </div> -->

                </div>
              </div>';

                        }
                        while ($row = mysql_fetch_array($querytao)) {
                        $temp = $row['img'];
                        $imgarr = explode(",", $temp);
                        $order_hotlevel_arr = '';
                        if ($row['hotlevel'] != 0) {
                            $order_hotlevel_arr[] = $row['hotlevel'];
                        }
                        ?>
                        <div class="bundle  bundle-last">

                            <div class="bundle-main">
                                <ul class="item-content clearfix">
                                    <div class="pay-phone">
                                        <li class="td td-item">
                                            <div class="item-pic">
                                                <a href="taogoodetail.php?id=<?php echo $row['goodid']; ?>"
                                                   class="J_MakePoint">
                                                    <img src="<?php echo $imgarr[0]; ?>" width="80" height="80"
                                                         class="itempic J_ItemImg"></a>
                                            </div>
                                            <div class="item-info">
                                                <div class="item-basic-info">
                                                    <a href="taogoodetail.php?id=<?php echo $row['goodid']; ?>"
                                                       class="item-title J_MakePoint"
                                                       data-point="tbcart.8.11"><?php echo $row['chtitle']; ?></a>
                                                </div>
                                            </div>
                                        </li>
                                        <li class="td td-info">
                                            <div class="item-props">
                            <span class="sku-line">

                                <?php if ($row['bunit']) {
                                    list($r1, $r2, $sku_price, $sku_store, $r3) = get_sku_info_by_id($row['bunit']);
                                    foreach ($r3 as $sk) {
                                        $sku_key_name = $sk['sku_key_name'];
                                        $sku_value_name = $sk['sku_value_name'];
                                        echo '<span style="float: left;margin-left: 60px">' . $sku_key_name . '：' . $sku_value_name . '</span><br>';
                                    }
                                } ?>
                            </span>
                                            </div>
                                        </li>
                                        <li class="td td-price">
                                            <div class="item-price price-promo-promo">
                                                <div class="price-content">
                                                    <em class="J_Price price-now"><?php echo floatval($row['gprice']); ?></em>
                                                </div>
                                            </div>
                                        </li>
                                    </div>
                                    <li class="td td-amount">
                                        <div class="amount-wrapper ">
                                            <div class="item-amount ">
                                                <span class="phone-title">购买数量</span>
                                                <div class="sl">
                                                    <em class="J_Price price-now"><?php echo $row['gnum']; ?></em>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                    <li class="td td-sum">
                                        <div class="td-inner">
                                            <em tabindex="0"
                                                class="J_ItemSum number"><?php echo floatval($row['totprice']); ?></em>
                                        </div>
                                    </li>
                                    <!--  <li class="td td-oplist">
                        <div class="td-inner">
                          <span class="phone-title">配送费</span>
                          <div class="pay-logis">
                            <b class="sys_item_freprice"><?php echo floatval($row['expresstri']); ?></b>元
                          </div>
                        </div>
                      </li> -->

                                </ul>
                                <div class="clear"></div>

                            </div>
                            <?php } ?>

                            <div class="clear"></div>
                        </div>

                    </div>
                    <!--订单结束 -->
                    <div class="pay-total">
                        <!--热销优惠券start -->
                        <? if ($flag2) { ?>
                            <div class="order-extra" style="width:100%;">
                                <div class="order-user-info" style="float:left;">
                                    <div id="holyshit257" class="memo">
                                        <label>热销优惠券使用：</label>
                                    </div>
                                </div>
                                <div style="float:right;">

                                    <select name="yhq_hot" id="yhq_hot">
                                        <option value="">选择优惠券</option>
                                        <!--25 -->

                                        <?php
                                        /**
                                         *        3  类产品，单笔订单满299元可抵扣25元优惠券；单笔订单满199元可抵扣10元优惠券；
                                         *        2  类产品，单笔订单满189元可抵扣20元优惠券；
                                         *        1  类产品，单笔订单满89元可抵扣3元优惠券；单笔订单满65元可抵扣2元优惠券；
                                         *        1+2   类产品，单笔订单满159元可抵扣10元优惠券；
                                         *        1+3   类产品，单笔订单满259元可抵扣10元优惠券；
                                         *        2+3   类产品，单笔订单满288元可抵扣25元优惠券；
                                         *        1+2+3 类产品，单笔订单满358元可抵扣25元优惠券；
                                         */
                                        $yhq_123 = [1, 2, 3];
                                        $yhq_23 = [2, 3];
                                        $yhq_13 = [1, 3];
                                        $yhq_12 = [1, 2];
                                        $yhq_1 = [1];
                                        $yhq_2 = [2];
                                        $yhq_3 = [3];

                                        $yhq_123_money = 358;
                                        $yhq_23_money = 288;
                                        $yhq_13_money = 259;
                                        $yhq_12_money = 159;
                                        $yhq_1_money_1 = 89;
                                        $yhq_1_money_2 = 65;
                                        $yhq_2_money = 189;
                                        $yhq_3_money_1 = 299;
                                        $yhq_3_money_2 = 199;

                                        $yhq_123_dk = 25;
                                        $yhq_23_dk = 25;
                                        $yhq_13_dk = 10;
                                        $yhq_12_dk = 10;
                                        $yhq_1_dk_1 = 3;
                                        $yhq_1_dk_2 = 2;
                                        $yhq_2_dk = 20;
                                        $yhq_3_dk_1 = 25;
                                        $yhq_3_dk_2 = 10;

                                        $order_hotlevel_arr = array_unique($order_hotlevel_arr);
                                        $goods_total_money = $rowfee['goods_total_money'];
                                        function check_in($a, $b)
                                        {
                                            if ($b == array_intersect($b, $a)) {
                                                return true;
                                            } else {
                                                return false;
                                            }
                                        }

                                        if (!empty($order_hotlevel_arr)) {
                                            if (check_in($order_hotlevel_arr, $yhq_123) && $goods_total_money >= $yhq_123_money) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_123_dk";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid' data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_23) && $goods_total_money >= $yhq_23_money) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_23_dk";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_13) && $goods_total_money >= $yhq_13_money) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_13_dk";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_12) && $goods_total_money >= $yhq_12_money) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_12_dk";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_1) && $goods_total_money >= $yhq_1_money_1) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_1_dk_1";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_1) && $goods_total_money >= $yhq_1_money_2) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_1_dk_2";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_2) && $goods_total_money >= $yhq_2_money) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_2_dk";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_3) && $goods_total_money >= $yhq_3_money_1) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_3_dk_1";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            } elseif (check_in($order_hotlevel_arr, $yhq_3) && $goods_total_money >= $yhq_3_money_2) {
                                                $sql = "select * from tbl_yhq where userid='" . $_COOKIE['userid'] . "' and state=1 and type=1 and UNIX_TIMESTAMP(lasttime)>UNIX_TIMESTAMP(now()) and money=$yhq_3_dk_2";
                                                $yhq_info = c_getRow($sql);
                                                if ($yhq_info) {
                                                    $mj = $yhq_info['money'];
                                                    $mid = $yhq_info['id'];
                                                    echo "<option value='$mid'  data-money = $mj style='text-align: center;' >代金券：￥$mj</option>";
                                                }
                                            }
                                        }


                                        ?>


                                    </select>

                                </div>
                            </div>
                        <? } ?>
                        <!--优惠券end -->

                        <!--运费 -->
                        <div class="order-extra" style="width:100%;">
                            <div class="order-user-info" style="float:left;">
                                <div id="holyshit257" class="memo">
                                    <label>运费：</label>
                                </div>
                            </div>
                            <div style="float:right;">
                                <?php echo floatval($rowfee['totexp']); ?>元
                            </div>
                        </div>

                        <!--发票 -->
                        <div class="order-extra" style="width:100%;">
                            <div class="order-user-info" style="float:left;">
                                <div id="holyshit257" class="memo">
                                    <label>是否开具发票：</label>
                                </div>
                            </div>
                            <div style="float:right;">
                                <input type="radio" class="recip" name="recip" value="1" title="是">是
                                <input type="radio" class="recip" name="recip" value="0" title="否" checked
                                       style="margin-left: 10px">否
                            </div>
                        </div>

                        <div class="order-extra" id="taxinput" style="display: none;width:100%;">
                            <div class="order-user-info" style="float:left;">
                                <div id="holyshit257" class="memo">
                                    <label>发票选择：</label>
                                </div>
                            </div>
                            <div style="float:right;">
                                <span id="cc1" onclick="cc1()" style="border: 1px solid #c3c3c3;padding:4px;">个人</span>
                                <span id="cc2" onclick="cc2()"
                                      style="border: 1px solid #c3c3c3;padding:4px;margin-left: 10px">企业</span>
                                <input type="hidden" id="sincom" value="">
                                <!-- <input type="radio" class="cc" value="1" checked>个人
                                <input type="radio" class="cc" value="0" style="margin-left: 10px">企业  -->
                            </div>
                        </div>

                        <div class="order-extra" id="dd" style="display: none;width:100%;">
                            <div class="order-user-info" style="float:left;">
                                <div id="holyshit257" class="memo">
                                    <label>发票填写：</label>
                                </div>
                            </div>
                            <div style="float:right;">
                                <input id="taxman" name="taxman" type="text" placeholder="请输入抬头名称" value=""/>
                            </div>
                        </div>

                        <div class="order-extra" id="ee" style="display: none;width:100%;">
                            <div class="order-user-info" style="float:left;">
                                <div id="holyshit257" class="memo">
                                    <label>发票填写：</label>
                                </div>
                            </div>
                            <div style="float:right;">
                                <input id="taxcom" name="taxcom" type="text" placeholder="请输入企业名称" value=""/>
                                <input id="taxconfig" name="taxconfig" type="text" placeholder="请填写纳税人识别号" value=""/>
                            </div>
                        </div>

                    </div>
                    <!--含运费小计 -->

                    <div class="buy-point-discharge ">
                        <input type="hidden" id="oripri" value="<?php echo $rowfee['totfee']; ?>">
                        <p class="price g_price ">
                            合计（含运费） <span>¥</span><em class="pay-sum" id="paysum"></em>
                        </p>
                    </div>
                    <div class="buy-point-discharge " id="showrecip" style="display: none;">
                        <p class="price g_price ">
                            税费 <span>¥</span><em class="pay-sum" id="totpri2"></em>
                        </p>
                    </div>
                    <div class="buy-point-discharge ">
                        <p class="price g_price ">
                            实付款 <span>¥</span><em class="pay-sum" id="realsum"></em>
                        </p>
                    </div>


                </div>
                <div id="holyshit269" class="submitOrder">
                    <div class="go-btn-wrap">
                        <p>
                            <button type="submit" class="am-btn am-btn-primary" style="float: right;">确认订单</button>
                        </p>
                    </div>
                </div>
                <div class="clear"></div>
            </div>

</form>

<? include('footerr.php'); ?>

<script type="text/javascript">

    var yhq = 0;
    var yhq_hot = 0;

    $('#yhq').change(function () {
        var str = $(this).val();
        var arr = str.split("and");
        yhq = arr[0];
    });

    $('#yhq_hot').change(function () {
        var m = $("#yhq_hot option:selected").attr('data-money');
        yhq_hot = m;
    });

    function Aaa() {

        var totfee = $('#oripri').val();
        var h = 0;
        var k = totfee - yhq - yhq_hot;
        $('#paysum').text(k);

        var obj = $(".recip");
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                if (obj[i].value == 1) {
                    h = k * 0.17;
                    h = h.toFixed(2);
                    $('#totpri2').text(h);
                    $('#showrecip').css("display", "block");
                    $('#taxinput').css("display", "block");
                } else {
                    h = 0;
                    $('#taxinput').css("display", "none");
                    $('#dd').css("display", "none");
                    $('#ee').css("display", "none");
                    $('#showrecip').css("display", "none");
                }
            }
        }

        j = parseFloat(h) + parseFloat(k);
        j = j.toFixed(2);
        if (j > 0) {
            $('#realsum').text(j);
        } else {
            $('#realsum').text(0);
        }
    }

    function cc1() {
        $('#cc1').css("background-color", "#019285").siblings().css("background-color", "#fff");
        $('#dd').css("display", "block");
        $('#ee').css("display", "none");
        $('#sincom').val(1);
    }
    function cc2() {
        $('#cc2').css("background-color", "#019285").siblings().css("background-color", "#fff");
        $('#dd').css("display", "none");
        $('#ee').css("display", "block");
        $('#sincom').val(2);
    }
</script>

<script type="text/javascript">
    function checktax() {

        var istax = $("input[name='recip']:checked").val();
        var sincom = $('#sincom').val();
        var taxman = $('#taxman').val();
        var taxcom = $('#taxcom').val();
        var taxconfig = $('#taxconfig').val();
        if (istax == 1) {
            if (sincom == 1) {
                if (taxman == "") {
                    alert("请填写个人发票信息!");
                    return false;
                }
            } else if (sincom == 2) {
                if (taxcom == "" || taxconfig == "") {
                    alert("请填写企业发票信息!");
                    return false;
                }
            }
        }
        return true;
    }

</script>

</body>
</html>